import { NodeSize } from '../config'

export default function selectValues(flow) {
  flow.register('SelectValues', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M532.72381 119.978667H76.068571v180.175238h456.655239v-180.175238z m-41.44762 138.727619H117.51619V161.401905h373.76v97.304381z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M117.51619 362.691048h788.96762v97.304381H117.51619z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M76.068571 321.26781v180.175238h871.862858v-180.175238H76.068571z m830.415239 138.727619H117.51619v-97.304381h788.96762v97.304381zM76.068571 904.021333h871.862858v-180.175238H76.068571v180.175238z m41.447619-138.727619h788.96762v97.304381H117.51619v-97.304381zM532.72381 522.581333H76.068571v180.175238h456.655239v-180.175238z m-41.44762 138.727619H117.51619v-97.304381h373.76v97.304381z'
            }
          ),
          h(
            'path',
            {
              fill: '#EA102A',
              d: 'M632.636952 306.883048l70.680381-70.680381 70.656 70.680381 32.768-32.768-70.680381-70.656 70.680381-70.680381-32.768-32.743619-70.656 70.656-70.680381-70.656-32.768 32.743619 70.680381 70.680381-70.680381 70.656zM632.636952 713.801143l70.680381-70.656 70.656 70.656 32.768-32.743619-70.680381-70.680381 70.680381-70.656-32.768-32.768-70.656 70.656-70.680381-70.656-32.768 32.768 70.680381 70.656-70.680381 70.680381z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          '字段选择'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
